<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
    </head>

    <body>

        <?php
        session_start();
        if (isset($_GET['paper_id'])) {

            $paper_id_d = $_GET['paper_id'];
            $conference_id = $_GET['conference_id'];

            //opening connection
            $conn = mysql_connect('localhost', 'root', '') or die(mysql_error());
            mysql_select_db('mydb') or die(mysql_error());
            // geting the version ID from Author's paper 
            // getting the last version of te paper
            $version_id = mysql_query(
                    "SELECT max(`version_id`)
            FROM version v 
            WHERE v.`paper_id` =$paper_id_d") or die(mysql_error());
            $row = mysql_fetch_assoc($version_id);
            $versionid = $row["max(`version_id`)"];
            $date = date('Y-m-d');
            $today = date("Y-m-d H:i:s", strtotime($date));
            $query= mysql_query("SELECT `status`
           FROM `paper`p
           WHERE`paper_id`='$paper_id_d'");
       $myrow=  mysql_fetch_assoc($query);
       $status=$myrow["status"];


            //getting the deadline
            $deadline = mysql_query("SELECT `rev_startDate` 
            From`conference`c   
            Where c.conference_id='$conference_id'
            ") or die(mysql_error());
            $row1 = mysql_fetch_assoc($deadline);
            $deadline_date = $row1["rev_startDate"];

            //updating table paper into deleted 
            if ($today < $deadline_date) {//checking if the the author is deleting before the deadline
                if($status!= "dismissed") {
                $query = mysql_query("Update `paper`p
                 SET `status` = 'deleted'
                 where p.`paper_id` = '$paper_id_d'
                ") or die(mysql_error());

                $query4 = mysql_query("Update `paper`p
                 SET `deleted` = TRUE
                 where p.`paper_id` = '$paper_id_d'
                ") or die(mysql_error());
                echo "The paper is successfully deleted";
                }
                else 
                {
                   echo"this paper has been already dismissed by the organizer";
                }
            }
            else {

                echo ("review process has started you cannot delete this paper");
            }




            mysql_close($conn);
        }
        ?>

    </body>

</html>
